﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace WindowsFormsApplication1.wtyczki
{
    class Binarysation
    {
        public static Bitmap BinaryThis(Bitmap bm)
        {
            int nValue;
            Bitmap bmTmp = new Bitmap(bm);
            using (ScrollBar form2 = new ScrollBar("Binarysation", 255))
            {
                form2.ShowDialog();
                nValue = form2.TheValue;
            }
            for (int y = 1; y < bm.Height; y++)
            {
                for (int x = 1; x < bm.Width; x++)
                {
                   double pointBright=0.299*bm.GetPixel(x,y).R+0.587*bm.GetPixel(x,y).G+0.114*bm.GetPixel(x,y).B;
                   if (pointBright > nValue)
                   {
                       bmTmp.SetPixel(x, y, Color.FromArgb(255, 255, 255));
                   }
                   else
                   {
                       bmTmp.SetPixel(x, y, Color.FromArgb(0, 0, 0));
                   }
                }
            }


            return bmTmp;
        }
        public static Bitmap BinaryThis(Bitmap bm,int Value)
        {
            int nValue = Value ;
            Bitmap bmTmp = new Bitmap(bm);
            
            for (int y = 1; y < bm.Height; y++)
            {
                for (int x = 1; x < bm.Width; x++)
                {
                    double pointBright = 0.299 * bm.GetPixel(x, y).R + 0.587 * bm.GetPixel(x, y).G + 0.114 * bm.GetPixel(x, y).B;
                    if (pointBright > nValue)
                    {
                        bmTmp.SetPixel(x, y, Color.FromArgb(255, 255, 255));
                    }
                    else
                    {
                        bmTmp.SetPixel(x, y, Color.FromArgb(0, 0, 0));
                    }
                }
            }


            return bmTmp;
        }
    }
}
